package cn.hchaojie.javase.day06;

import java.util.Date;
import java.util.Objects;

/**
 * 父类
 * 
 * @author hchaojie
 *
 */
public class Employee {
	private String name;
	private int age;
	protected char gender;
	
	// 不加任何访问修饰符、便是包访问权限（同样一个包里面，可以访问）
	// 
	Date onboard;
	
	public Employee() {
		
	}
	
	public Employee(String name) {
		this.name = name;
		System.out.println("带参数的构造器被调用了。。。");
	}
	
	private double salary;
	
	/**
	 * protected: 守保护的方法
	 * @param c
	 */
	protected void setGender(char c) {
		this.gender = c;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}

	public double getSalary() {
		System.out.println("父类的getSalary方法");
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}
	
	@Override
	public boolean equals(Object obj) {
		// 比较两个对象的[所有属性]是否一致, name\age\gender
		if (this == obj) {
			return true;
		}
		
		if (!(obj instanceof Employee)) {
			return false;
		}
				
		// 走到这里，obj肯定是一个Employee类型的对象
		Employee other = (Employee) obj;
		
		if (this.age != other.age) {
			return false;
		}
		
		if (this.gender != other.gender) {
			return false;
		}
		
//		if (this.name == null) {
//			if (other.name != null) {
//				return false;
//			}
//		} else {
//			if (!this.name.equals(other.name)) {
//				return false;
//			}
//		}
		// return (a == b) || (a != null && a.equals(b));
		
		if (!Objects.equals(this.name, other.name)) {
			return false;
		}

		return true;
	}

	@Override
	public String toString() {
		return "Employee [name=" + name + ", age=" + age + ", gender=" + gender + "]";
	}
	
	
}
